package com.tping.thread;

import java.util.List;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

public class CyclicThread implements Runnable {

    String sign;
    CyclicBarrier cyclic;
    List<String> list;

    CyclicThread(CyclicBarrier cyclic, List<String> list, String sign){
        this.cyclic = cyclic;
        this.list = list;
        this.sign = sign;
    }

    @Override
    public void run() {
        for (int i = 0; i < 5; i++) {
            list.add(sign + "_" + i);
        }

        System.out.println(Thread.currentThread().getName() + "操作完毕...进入wait");
        try {
            cyclic.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (BrokenBarrierException e) {
            e.printStackTrace();
        }
    }
}
